package com.pig4cloud.pigx.robot.ws.collect.bitmex;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;

import javax.annotation.Nullable;

@Slf4j
public class WsListener  extends WebSocketListener {


	public void WsListener() {

	}
	@Override
	public void onOpen(WebSocket webSocket, Response response) {
		log.info("bitmex websocket onOpen... ");
		WsManager.getInstance().isConnect = true;
		WsManager.getInstance().onSubscribe();
	}
	@Override
	public void onMessage(WebSocket webSocket, String text) {
//		log.info("bitmex ... ");
 		//log.info(text);
		ParseData.parse(text);
	}
	@Override
	public void onMessage(WebSocket webSocket, ByteString bytes) {
		log.info("binance websocket onMessage... ");
	}
	@Override
	public void onClosing(WebSocket webSocket, int code, String reason) {
		log.info("bitmex websocket onClosing... ");
		WsManager.getInstance().onClose();

	}
	@Override
	public void onClosed(WebSocket webSocket, int code, String reason) {
		log.info("bitmex websocket onClosed... ");
		WsManager.getInstance().onClose();
	}
	@Override
	public void onFailure(WebSocket webSocket, Throwable t, @Nullable Response response) {
		log.info("bitmex websocket onFailure... ");

		if (response != null) {
			log.info("bitmex WebSocket onFailure：" + response.message());
		}
		if(t != null){
			log.info("bitmex WebSocket onFailure：" + t.getMessage());
		}


		WsManager.getInstance().onClose();

	}





}
